const { merge } = require('webpack-merge')
const common = require('./webpack.common')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const TerserWebpackPlugin = require('terser-webpack-plugin')

module.exports = merge(common, {
  mode: 'none',
  optimization: {
    splitChunks: {
      chunks: 'all'
    },
    minimize: true,
    minimizer: [
      new TerserWebpackPlugin({
        test: /\.js(\?.*)?$/i, // 匹配参与压缩的文件
        parallel: true, // 使用多进程并发运行
        terserOptions: {
          // Terser 压缩配置
          output: { comments: false }
        },
        extractComments: true // 将注释剥离到单独的文件中
      })
    ]
  },
  plugins: [
    new CopyWebpackPlugin({ patterns: ['public'] }),
    new MiniCssExtractPlugin()
  ]
})
